//
//  UIViewAnimations2ViewController.m
//  Animations
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "UIViewAnimations2ViewController.h"

@interface UIViewAnimations2ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *planImageView;

@end

@implementation UIViewAnimations2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 2. UIView 隐式动画
// 创建视图内视图对象的动画效果的简单方式
// 可修改的属性:
// * 位置、尺寸大小
// * 透明度
// * transform变换(位移、旋转)


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //方式1
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:3];

    // 中止值
    CGPoint center = self.planImageView.center;
    center.x += 100;
    center.y += 100;
    self.planImageView.center = center;

    [UIView commitAnimations];
    
//    //方式2 block方式
//    [UIView animateWithDuration:5
//                          delay:0.5
//         usingSpringWithDamping:1
//          initialSpringVelocity:5
//                        options:UIViewAnimationOptionCurveLinear
//                     animations:^{
//                         CGPoint center = self.planImageView.center;
//                         center.x += 100;
//                         center.y += 200;
//                         self.planImageView.center = center;
//                     }
//                     completion:^(BOOL finished) {
//                         // 动画执行完之后，执行的代码
//                     }];
}

@end
